$(function(){
    $("#topBtn").click(setTop);
    $("#wonderfulBtn").click(setWonderful);
    $("#deleteBtn").click(setDelete);
});


function like(btn, entityType, entityId,entityUserId, postId) {

    $.post(
        "/community/like",
        {"entityType":entityType,"entityId":entityId,"entityUserId":entityUserId,"postId":postId},
        function(data) {
            data = $.parseJSON(data);
            if(data.code == 0) {
                $(btn).children("i").text(data.likeCount);
                $(btn).children("b").text(data.likeStatus==1?'已赞':"赞");
            } else {
                alert(data.msg);
            }
        }
    );
}



// 置顶
function setTop() {
    console.log("top");
    $.post(
          "/community/discuss/top",
        {"id":$("#postId").val()},
        function(data) {
            data = $.parseJSON(data);
            if(data.code == 0) {
                $("#topBtn").attr("disabled", "disabled");
            } else {
                alert(data.msg);
            }
        }
    );
}

// 加精
function setWonderful() {

    $.post(
         "/community/discuss/wonderful",
        {"id":$("#postId").val()},
        function(data) {
            data = $.parseJSON(data);
            if(data.code == 0) {
                console.log("setWonderful");
                $("#wonderfulBtn").attr("disabled", "disabled");
            } else {
                console.log("22222222");
                alert(data.msg);
            }
        }
    );
}

// 删除
function setDelete() {
    console.log("setDelete");
    $.post(
       "/community/discuss/delete",
        {"id":$("#postId").val()},
        function(data) {
            data = $.parseJSON(data);
            if(data.code == 0) {
                location.href = "/community/index";
            } else {
                alert(data.msg);
            }
        }
    );
}